using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.BO.Editoral.NewsEditModules;

namespace Portal.GUI.EditoralOffice.MainOffce.NewsEditModules.ImagesModule
{
    public partial class ImagesModule : Portal.BO.Editoral.NewsEditModules.NewsModule
    {
        protected string returnScript = "";
        //private string configFileLocation = "/GUI/EditoralOffice/MainOffce/NewsEditModules/ImagesModule";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["newsid"] == null || Convert.ToString(Session["newsid"]).Trim() == "")
                    Session["newsid"] = DateTime.Now.Year + "" + DateTime.Now.Month + DateTime.Now.Day + "" + DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second + DateTime.Now.Millisecond;
            }
        }

        private void bindData()
        {
            LoadRuntimeSettings();
            txtSelectedFile.Text = Convert.ToString(ReadRuntimeConfig(true, "ImagePath"));
            txtImageLink.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageLink"));
            drpImageLinkTarget.SelectedValue = Convert.ToString(ReadRuntimeConfig(true, "ImageTargetType"));
            txtImageWidth.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageWidth"));
            txtImageHeight.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageHeight"));
            try
            {
                drpImageHorizontal.SelectedValue = Convert.ToString(ReadRuntimeConfig(true, "ImageHorizontalPosition"));
            }
            catch { }
            try
            {
                drpImageVertical.SelectedValue = Convert.ToString(ReadRuntimeConfig(true, "ImageVerticalPosition"));
            }
            catch { }
            txtBorderWidth.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageBorderWidth"));
            txtBorderColor.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageBorderColor"));
            txtBorderStyle.Text = Convert.ToString(ReadRuntimeConfig(true, "ImageBorderStyle"));
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            save();
            //returnScript = "returnValue('" + module.ConfigFileLocation + "', '" + module.ModuleReference + "', '');";
			((Portal.GUI.EditoralOffice.MainOffce.editnews.editModule)this.Page).loadPresentationModule(ModuleType, ModuleRef);
        }

        public override void SaveAllProperties()
        {
            save();
        }

        private void save()
        {
            PortalDefinition.Module module = new PortalDefinition.Module();
            module.reference = this.ModuleRef;
            module.type = this.ModuleType;
            module.LoadRuntimeProperties();

            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImagePath", txtSelectedFile.Text.Trim());
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageLink", txtImageLink.Text.Trim());
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageTargetType", drpImageLinkTarget.SelectedValue);
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageWidth", txtImageWidth.Text.Trim());
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageHeight", txtImageHeight.Text.Trim());
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageHorizontalPosition", drpImageHorizontal.SelectedValue);
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageVerticalPosition", drpImageVertical.SelectedValue);
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageBorderWidth", txtBorderWidth.Text);
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageBorderColor", txtBorderColor.Text);
            module.moduleRuntimeSettings.SetRuntimePropertyValue(true, "ImageBorderStyle", txtBorderStyle.Text);

            module.SaveRuntimeSettings();
        }
    }
}